<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>登录 | 学生管理系统 | 菜鸟基地</title>
</head>

<body>
    <div class="container">
        <div>
            <label for="login_acco">账号：</label>
            <input id="login_acco" type="text">
        </div>
        <div>
            <label for="login_password">密码：</label>
            <input id="login_password" type="password">
        </div>
        <div>
            <button id="login">登录</button>
        </div>
    </div>
    <script src="https://cdn.bootcss.com/jquery/1.9.1/jquery.min.js"></script>
    <script>
        $(function () {
            $('#login').click(function () {
                var login_acco = $.trim($('#login_acco').val());
                var login_password = $.trim($('#login_password').val());
                if (login_acco === '') {
                    alert('账号不能为空');
                    return;
                }
                if (login_password === '') {
                    alert('密码不能为空');
                    return;
                }
                $.post('/api/login', {
                    "login_acco": login_acco,
                    "login_password": login_password
                }, function (res) {
                    if (res.code !== 1) {
                        alert(res.msg);
                        return;
                    }
                    alert('欢迎' + res.data.name + '登陆');
                    window.location.href = '/students';
                }, 'json');
            });
        });
    </script>
</body>

</html>